package cn.it.hbtt.untils;

import org.springframework.core.convert.converter.Converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateConverter implements Converter<String, Date> {

    private String pattern;

    public DateConverter(String pattern){
        this.pattern=pattern;
    }
    @Override
    public Date convert(String source) {

            SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);

            try {
                Date date = dateFormat.parse(source);
                return date;
            } catch (ParseException e) {
                e.printStackTrace();
            }
        return null;
    }
}
